import { defineStore } from 'pinia'
import { useSystemStore } from '@/pinia/system'
const systemStore = useSystemStore()
export const savePathStore = defineStore('savePath', () => {
  //选择保存路径
  const saveAudio = async () => {
    const folderPath = await window.electron.ipcRenderer.invoke(
      'show-open-folder-dialog',
      '请选择保存文件的路径',
      '选择文件夹'
    )
    if (folderPath) {
      systemStore.editstore({
        audioFile: folderPath
      })
      window.electron.ipcRenderer.send('cross-window-message', {
        channel: 'useSystemStore',
        data: {
          fileStorage: {
            audioFile: folderPath
          }
        }
      })
    }
    return folderPath
  }
  //保存文件
  const saveData = async (data: any, type: number = 0, title: string = '未命名文件') => {
    if (type === 0) {
      return  window.electron.ipcRenderer.send('save-file', data, title, systemStore.fileStorage.audioFile)
    }
  }
  return {
    saveAudio,
    saveData
  }
})
